package com.cjhhv.visual.controller;

import cn.hutool.core.util.ObjectUtil;
import com.cjhhv.base.model.ResponseDataModel;
import com.cjhhv.base.util.ResponseDataUtil;
import com.cjhhv.visual.model.DashboardThemeModel;
import com.cjhhv.visual.service.DashboardThemeService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/dashboardTheme")
public class DashboardThemeController {

   private DashboardThemeService dashboardThemeService;


    @GetMapping("/queryDashboardThemeById")
    @ResponseBody
    public ResponseDataModel queryDashboardThemeById(@RequestParam("id") String id ){
        DashboardThemeModel dashboardThemeModel = this.dashboardThemeService.queryDashboardThemeById(id);
        if(ObjectUtil.isNotEmpty(dashboardThemeModel)){
            return ResponseDataUtil.createResponseData(true,"查询成功!",dashboardThemeModel);
        }else{
            return ResponseDataUtil.createResponseData(false,"查询失败!",null);
        }
    }

    @PostMapping("/queryDashboardThemePageList")
    @ResponseBody
    public ResponseDataModel queryDashboardThemePageList(@RequestBody DashboardThemeModel parameter){
        PageInfo<DashboardThemeModel> pageInfo = this.dashboardThemeService.queryDashboardThemePageList(parameter);
        return ResponseDataUtil.createResponseData(true,"查询成功!",pageInfo);
    }

    @GetMapping("/queryDashboardThemeList")
    @ResponseBody
    public ResponseDataModel queryDashboardThemeList(){
        List<DashboardThemeModel> list = this.dashboardThemeService.queryDashboardThemeList();
        return ResponseDataUtil.createResponseData(true,"查询成功!",list);
    }

    @PostMapping("/saveDashboardTheme")
    @ResponseBody
    public ResponseDataModel saveDashboardTheme(@RequestBody DashboardThemeModel parameter){
        int count = this.dashboardThemeService.saveDashboardTheme(parameter);
        if(count==-1){
            return ResponseDataUtil.createResponseData(false,"主题已存在!",null);
        }else if(count>0){
            return ResponseDataUtil.createResponseData(true,"保存成功!",null);
        }else{
            return ResponseDataUtil.createResponseData(false,"保存失败!",null);
        }
    }

    @DeleteMapping("/deleteDashboardThemeByIds")
    @ResponseBody
    public ResponseDataModel deleteDashboardThemeByIds(@RequestBody DashboardThemeModel parameter) {
        int count =  this.dashboardThemeService.deleteDashboardThemeByIds(parameter);
        if(count>0){
            return ResponseDataUtil.createResponseData(true,"删除成功!",null);
        }else {
            return ResponseDataUtil.createResponseData(false,"删除失败!",null);
        }
    }

    public DashboardThemeService getDashboardThemeService() {
        return dashboardThemeService;
    }

    @Autowired
    public void setDashboardThemeService(DashboardThemeService dashboardThemeService) {
        this.dashboardThemeService = dashboardThemeService;
    }
}
